package com.lc.stock.module.filtrate.filter.impl;

import cn.hutool.core.util.StrUtil;
import com.lc.stock.module.companyinfo.dao.CompanyInfoDao;
import com.lc.stock.module.companyinfo.domain.CompanyInfo;
import com.lc.stock.module.filtrate.filter.FiltrateStockFilter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author lichen
 * @description 筛选出非ST股票
 * @menu
 * @date 2023/2/6 11:37
 */
@Slf4j
@Component
public class STFilter implements FiltrateStockFilter {

    @Autowired
    private CompanyInfoDao companyInfoDao;

    @Override
    public boolean doFilter(String stockCode) {
        CompanyInfo companyInfo = companyInfoDao.findByStockCode(stockCode);
        if(null == companyInfo){
            return true;
        }
        //证券简称更名历史
        String oname = companyInfo.getOname();
        if(StrUtil.isNotEmpty(oname)){
            String[] onameArray = oname.split(" ");
            String lastOname = onameArray[onameArray.length - 1];
            if(lastOname.indexOf("ST")>-1){
                return false;
            }
        }
        return true;
    }

    public String getErrorMsg(){
        return "公司是ST股票;";
    }
}
